package mapreduce;

/**
 * This contains the basic class to give operation around points
 */

public class Point {
	double x, y;
	String str = null;
	final static String sep = ",";

	
	public Point(double x, double y) {
		super();
		this.x = x;
		this.y = y;
		if(str==null)
			str = toString();
	}

	public double distanceFrom(Point point) {
		double x = point.getx();
		double y = point.gety();
		return Math.sqrt(Math.pow(this.x - x, 2) + Math.pow(this.y - y, 2));
	}

	public double getx() {
		return x;
	}

	public double gety() {
		return y;
	}

	public String toString() {
		if(str == null)
			str = x + sep + y;
		return str;
	}
	
	static public Point fromString(String arg) {
		String []s = arg.split(sep);
		Point p = new Point(Double.parseDouble(s[0]), Double.parseDouble(s[1]));
		return p;
	}
	
}

